package restaurant.selector.server;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import restaurant.selector.logic.LogicInterface;

public class ServerHandler implements Runnable {

	private final String EOL = "\r\n";
	private final String BANNER = EOL + EOL + "Today's lunch will be" + EOL + "***** ";
	
	private Socket socket;
	private LogicInterface logic;
	
	public ServerHandler( Socket socket, LogicInterface logic ){
		this.socket = socket;
		this.logic = logic;
	}
	
	@Override
	public void run() {

		try{
			InputStream in = socket.getInputStream();
			OutputStream out = socket.getOutputStream();
		
			// we don't care what you send us...
			byte[] buffer = new byte[1024];
			in.read(buffer);
			
			String restaurant = logic.getRestaurant();
			
			out.write(BANNER.getBytes());
			out.write(restaurant.getBytes() );
			out.write((" *****"+EOL+EOL).getBytes());
			out.flush();
			
			socket.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
